<% title_tag(@page_title || t('menu.topics')) %>

<!-- @suggest_topics maybe nil or ActiveRecord::Relation, but we need an array -->
<% @suggest_topics = @suggest_topics.to_a %>

<div class="row">
  <div class="col-md-9">
    <div class="topics panel panel-default">
      <div class="topic-list-heading panel-heading clearfix">
        <%= render "topics/node_info", node: @node %>
      </div>

      <div class="panel-body item-list">
        <% if @suggest_topics.present? %>
          <%= render partial: '/topics/topic', collection: @suggest_topics, locals: { suggest: true }, cached: -> (topic) { [topic, 'suggest'] } %>
        <% end %>

        <%= render partial: '/topics/topic', collection: @topics, locals: { suggest: false }, cached: -> (topic) { [topic, 'normal'] } %>
      </div>

      <div class="panel-footer clearfix">
        <%= will_paginate @topics %>
      </div>

    </div>

    <% if controller_name == "topics" && action_name == "index" && !mobile? %>
      <%= render "/shared/index_sections" %>
      <%= render "/shared/hot_locations" %>
    <% end %>

    <% if current_user %>
    <script type="text/javascript">
      var readed_topic_ids = <%= current_user.filter_readed_topics(@topics + @suggest_topics) %>;
      for (var i = 0; i < readed_topic_ids.length; i++) {
        topic_id = readed_topic_ids[i];
        $(".topic-"+ topic_id).addClass('topic-visited');
        $(".topic-"+ topic_id + " .count a").addClass("state-true");
      }
    </script>
    <% end %>
  </div>


  <div class="sidebar col-md-3">
    <%= render "topics/sidebar_for_topic_index" %>
  </div>

</div>
